clear all
set	more off

cd "~/Dropbox/ors_quality_R01"
use "data/KDG/know_do_gap.dta", clear

//Table 1

g ps_rmp=(ps_b03==2|ps_b03==3)
g ps_ayush=(ps_b03==4)
replace ps_b07=0 if ps_b07==2
//g ps_pharm=(ps_b03==5)

//la var ps_b06 "Age"
la var ps_b06 "\midrule\shortstack[l]{\textbf{Demographics}\\\hspace{0.2cm}Age}"
la var ps_b07 "\hspace{0.2cm}Male"
la var ps_b11  "\shortstack[l]{\textbf{Knowledge/Experience}\\\hspace{0.2cm}Years of experience}"
la var know_ors "\hspace{0.2cm}Correct ORS Knowledge"
la var know_anti "\hspace{0.2cm}Correct Abx Knowledge"
la var ps_mbbs "\shortstack[l]{\textbf{Provider type}\\\hspace{0.2cm}MBBS}"
la var ps_rmp "\hspace{0.2cm}RMP"
la var ps_ayush "\hspace{0.2cm}AYUSH"
la var ps_pharm "\hspace{0.2cm}Pharmacy"
la var ps_b37  "\shortstack[l]{\textbf{Patient volume}\\\hspace{0.2cm}Patients per day}"
la var ps_b39 "\hspace{0.2cm}Diarrhea case per week"
la var ps_b28 "\shortstack[l]{\textbf{Facility characteristics}\\\hspace{0.2cm}Number of beds}" 
la var ps_b55 "\hspace{0.2cm}Consultation Fee"
la var ps_dispense "\hspace{0.2cm}Dispenses medications"
la var ps_b62 "\hspace{0.2cm}ORS available at baseline"

//la var ps_b29 "Has electricity"
//la var ps_b18 "Works at other facility"
//la var ps_price_ORS "Fee for ORS (if available)"

preserve

drop if rec_ors==.

replace ps_b39=0 if ps_b39==-87
*Count
egen count_group= count(state_name) if state_name!="", by (state_name)
la var count_group "Observations"

g pharm=ps_b05==3
replace pharm=. if ps_b05==.
label variable pharm "Provider is a pharmacy"

global sum_vars ps_b06 ps_b07 ps_b11 know_anti know_ors ps_mbbs ps_rmp ps_ayush ps_pharm ps_b37 ps_b39 ps_b28 ps_b55 ps_dispense ps_b62
count 
mat tab = ( r(N) , . )

g st_cat=state_name=="Karnataka"


tab count_group, matcell(x)
svmat x
local kar_c=x[1]
local bihar_c=x[2]
local total_c=x[1]+x[2]



mata: tab = ( "Variables", "\shortstack{Pooled\\(N=`total_c')}", "\shortstack{Karnataka\\(N=`kar_c')}", "\shortstack{Bihar\\(N=`bihar_c')}")

foreach var of varlist $sum_vars{

	local var_lab : variable label `var'
	sum `var'
	local mean1 : di %3.2f r(mean)
	
	
	sum `var' if state_name=="Karnataka"
	local mean2 : di %3.2f r(mean)
	

	
	sum `var' if state_name=="Bihar"
	local mean3 : di %3.2f r(mean)
	


	
	
	*formatting numbers
	foreach stat in mean1 mean2 mean3 {
	local `stat' = substr("``stat''",  1, 4)
	if strpos("``stat''", ".")==1{ 
	local `stat' = "0``stat''"
	}
	}
	
	mata: `var' = ("`var_lab'",  "`mean1'" ,  "`mean2'" ,   "`mean3'")
	
	mata: tab = (tab \ `var' )
	
	
	}
	drop count_group 
	
	mmat2tex tab using "tex_tables/summary_stats_antibiotics.tex", replace
	

restore

	
	
	
